package com.wrb.pwd.constant;


import com.alibaba.fastjson.JSONObject;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;

/**
 * @author wrb
 * @date 2019/10/9 10:49
 */
public class Constant {

	public static String password;

	public static final String DATA_FILE_NAME = "user_db.txt";

	public static final String PASSWORD_FILE_NAME = "password.json";

	static {
		try {
			InputStream in = Constant.class.getResourceAsStream("/" + Constant.PASSWORD_FILE_NAME);
			ByteArrayOutputStream result = new ByteArrayOutputStream();
			byte[] buffer = new byte[1024];
			int length;
			while ((length = in.read(buffer)) != -1) {
				result.write(buffer, 0, length);
			}
			String text = new String(buffer, StandardCharsets.UTF_8);
			password = (String) JSONObject.parse(text);
		} catch (IOException e) {
			throw new IllegalArgumentException("获取密码失败");
		}
	}
}
